#!/bin/bash

CONTAINER_NAME="redis" # Replace with your container name

# Function to check if a docker container is running
is_container_running() {
    container_name=$1
    if [ "$(docker ps -q -f name=^/${container_name}$)" ]; then
        return 0
    else
        return 1
    fi
}

# Step 1: Check for Docker
if ! command -v docker &> /dev/null; then
    echo "Docker is not installed. Please install Docker and try again."
    exit 1
fi

# Step 2: Check for Docker Compose
if ! command -v docker-compose &> /dev/null; then
    echo "Docker Compose is not installed. Please install Docker Compose and try again."
    exit 1
fi

# Step 3: Check if specified Docker container is running
if is_container_running $CONTAINER_NAME; then
    echo "Docker container '$CONTAINER_NAME' is already running."
    exit 1
else
    echo "Docker container '$CONTAINER_NAME' is not running."
fi

# Step 4: Start the application using Docker Compose
echo "Starting the application with Docker Compose..."
docker-compose up -d

# Print the current server IP address
IP_ADDRESS=$(hostname -I | awk '{print $1}')

echo "Application started successfully."
echo "================================================"
echo "Redis Host: ${IP_ADDRESS}"
echo "Redis Port: 6379"
echo "Redis User: root"
echo "Redis Pwd : Hzsun@310012"
echo "================================================"
